package com.longcai.piaojia.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.TextView;

import com.longcai.piaojia.R;
import com.longcai.piaojia.fragment.FragmentMyCollection;
import com.zcx.helper.bound.BoundView;

/**
 * Created by Administrator on 2016/8/2.
 */
public class MyCollectionListActivity extends BaseActivity implements View.OnClickListener {

    @BoundView(R.id.mycollection_ticket_order_tv) private TextView mycollection_ticket_order_tv;
    @BoundView(R.id.mycollection_merchant_collection_tv) private TextView mycollection_merchant_collection_tv;
    @BoundView(R.id.mycollection_commodity_collection_tv) private TextView mycollection_commodity_collection_tv;

    private FragmentMyCollection fragmentMyCollection;

    private Fragment[] fragments;

    private int prePosition;

    private int index;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_mycollection);

        setBackTrue();

        setTitleName(getString(R.string.mycollection_title_text));

        mycollection_ticket_order_tv.setOnClickListener(this);
        mycollection_merchant_collection_tv.setOnClickListener(this);
        mycollection_commodity_collection_tv.setOnClickListener(this);

        fragmentMyCollection = new FragmentMyCollection();

//        mycollection_ticket_order_tv.performClick();

        fragments = new Fragment[]{fragmentMyCollection};

        getSupportFragmentManager().beginTransaction().add(R.id.mycollection_container_rl, fragmentMyCollection)
                .show(fragmentMyCollection).commit();
        mycollection_ticket_order_tv.setTextColor(getResources().getColor(R.color.pale_red_color));

    }

    @Override
    public void onClick(View view) {

        FragmentTransaction trx = getSupportFragmentManager().beginTransaction();

        switch (view.getId()) {

            case R.id.mycollection_ticket_order_tv:

//                index = 0;
//
//                if (prePosition != index) {
//
//                    initTextColor();
//                    mycollection_ticket_order_tv.setTextColor(getResources().getColor(R.color.pale_red_color));
//
//                    trx.hide(fragments[prePosition]);
//                    if (!fragments[index].isAdded()) {
//                        trx.add(R.id.mycollection_container_rl, fragments[index]);
//                    }
//                    trx.show(fragments[index]).commit();
//
//                    prePosition = index;
//
//                }

                initTextColor();
                mycollection_ticket_order_tv.setTextColor(getResources().getColor(R.color.pale_red_color));
                trx.replace(R.id.mycollection_container_rl, fragmentMyCollection);

                trx.commit();

                break;

            case R.id.mycollection_merchant_collection_tv:
                initTextColor();
                mycollection_merchant_collection_tv.setTextColor(getResources().getColor(R.color.pale_red_color));

                index = 1;
                prePosition = index;
                break;

            case R.id.mycollection_commodity_collection_tv:
                initTextColor();
                mycollection_commodity_collection_tv.setTextColor(getResources().getColor(R.color.pale_red_color));

                index = 2;
                prePosition = index;
                break;

        }


    }

    private void initTextColor() {
        mycollection_ticket_order_tv.setTextColor(getResources().getColor(R.color.text_color));
        mycollection_merchant_collection_tv.setTextColor(getResources().getColor(R.color.text_color));
        mycollection_commodity_collection_tv.setTextColor(getResources().getColor(R.color.text_color));
    }

}
